#include "stdafx.h"
#include "CalcAnimation.h"
#include "View.h"
#include "WidgetWin.h"

CalcAnimation::CalcAnimation(int max_step, int grain)
	: Animation(max_step, grain)
	, is_cancel_(false)
	, step_num_(0)
{
}


CalcAnimation::~CalcAnimation()
{
}


void CalcAnimation::start(View* view)
{
	object_view_ = view;
	startAnimation();

	is_cancel_ = false;
}

void CalcAnimation::cancel()
{
	is_cancel_ = true;
}

int CalcAnimation::getCalc()
{
	return step_num_;
}

bool CalcAnimation::step(int step_num)
{
	RECT rc;
	rc.left = object_view_->X();
	rc.top = object_view_->Y();
	rc.right = object_view_->X() + object_view_->Width();
	rc.bottom = object_view_->Y() + object_view_->Height();

	step_num_ = step_num;
	::InvalidateRect(WidgetWin::getInstance().getNativeHwnd(), &rc, false);

	// ATLTRACE("[%s][%d][%d][%d]\r\n", __FUNCTION__, __LINE__, step_num, Time::now());

	return !is_cancel_;
}
